<template>
	<view class="container">
		<view class="title">
			奶茶商城注册
		</view>
		<input type="text" v-model="userInfo.utell" placeholder="请输入用户名">
		<input type="password" v-model="userInfo.upwd" placeholder="请输入密码">
		<button class="btn" @click="register">
			立即注册
		</button>
		<button class="btn" @click="toLoginPage">
			跳转登录
		</button>
		<button class="btn" @click="toBack">
			返回
		</button>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				userInfo: {
					utell: "",
					upwd: ""
				}

			}
		},
		methods: {
			toLoginPage() {
				uni.navigateTo({
					url: "/pages/login/login"
				})
			},
			register() {
				console.log(this.userInfo);
				uni.request({
					//请求路径
					url: "http://47.96.80.123:8000/user/registerUtell",
					method: 'POST',
					data: this.userInfo,
					header: {
						"Content-Type": "application/x-www-form-urlencoded"
					},
					//回调函数
					success: (res) => {
						console.log(res)

						if (res.data.code === "0") {
							uni.showToast({
								title: res.data.msg,
								duration: 2000,
								icon: "fail"
							});

							setTimeout(() => {
								uni.navigateTo({
									url: "/pages/login/login"
								})
							}, 2000)

						} else {
							uni.showToast({
								title: res.data.msg,
								duration: 2000,
								icon: "error"
							})

						}

					}
				})
			},
			toBack() {
				uni.navigateBack()
			}
		}
	}
</script>

<style scoped>
	uni-input {
		height: 45px;
		width: 80%;
		font-weight: bold;
		border-radius: 10px;
		padding: 3px 10px;
		margin: 0 auto;
		border: 1px solid #cccc;
		box-sizing: border-box;
		margin-bottom: 30px;
		margin-top: 30px;
	}

	button {
		width: 80%;
		font-weight: bold;
		border-radius: 10px;
	}

	.btn {
		background: darksalmon;
		color: #fff;
		margin-bottom: 20px;
	}

	.title {
		font-size: 25px;
		text-align: center;
		margin-top: 25px;
		font-weight: bold;
		color: darksalmon;
	}
</style>